import requests

from public.public_function import writer_log
from public.public_variable import headers


class Base:
 def send_requests(self,method,url,json=None,data=None,parmas=None):
     response =None
     try:
         if method == 'post':
             writer_log(f'请求方法：【post】,url:【{url}】,json:【{json}】,data:【{data}】,请求头：【{headers}】')
             response=requests.post(url=url,json=json,data=data,headers=headers)

         elif method == 'get':
             writer_log(f'请求方法：【get】,url:【{url}】,parmas:【{parmas}】,请求头：【{headers}】')
             response=requests.get(url=url,params=parmas,headers=headers)
     except BaseException as e:#报错信息数据类型不是字符串，要将报错信息转换成字符串
         writer_log(str(e))
         print(e)
     else:
         res_code = response.status_code
         rebody=response.json()
         writer_log(f'响应码：【{res_code}】,响应体：【{rebody}】')
         return res_code,rebody

